// Constants for convenience
if (typeof(Cc) == "undefined")
  var Cc = Components.classes;
if (typeof(Ci) == "undefined")
  var Ci = Components.interfaces;
if (typeof(Cu) == "undefined")
  var Cu = Components.utils;
if (typeof(Cr) == "undefined")
  var Cr = Components.results;
	
Cu.import("resource://telescope/modules/Preferences.js"); 

if (!telescope) var telescope = {};
telescope.welcome = {
	myHostName: '',
	initialize: function() {
	
		var linkEl = document.getElementById('pageURL');
		var ipEl = document.getElementById('ipaddr');
		var hostName = telescope.welcome.getHostName();
		var hostIP = telescope.welcome.getHostIP();
		var port = Preferences.get("extensions.telescope.port",3690);
		var hostNameLink = 'http://' + hostName + ':' + port + '/';
		
		linkEl.href= hostNameLink;;
		linkEl.innerHTML = hostNameLink + ' (Click me to try!)';
		ipEl.innerHTML = hostName;
	},
	getHostName: function()
	{
		var DNSService = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
		
		return DNSService.myHostName;
	},
	getHostIP: function()
	{
		var DNSService = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
		
		return DNSService.resolve(DNSService.myHostName, 0).getNextAddrAsString();
	},
	shutdown: function() {
	},
}
window.addEventListener("load", telescope.welcome.initialize, false);
window.addEventListener("unload", telescope.welcome.shutdown, false);